package com.example.springboot.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.controller.dto.FollowDTO;
import com.example.springboot.controller.dto.LikesDTO;
import com.example.springboot.entity.Follows;
import com.example.springboot.entity.Likes;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 用户点赞表 Mapper 接口
 * </p>
 *
 * @author
 * @since
 */
public interface LikesMapper extends BaseMapper<Likes> {

    //作者：author_id  文章id：article_id
    @Select("SELECT " +
            "a.*, " +                           // 点赞记录字段
            "author.nickName AS nickName, " +   // 文章作者的昵称
            "author.avatar_url AS avatar, " +    // 文章作者的头像
            "ar.* " +                           // 文章的所有字段（可按需调整）
            "FROM likes a " +
            "LEFT JOIN articles ar ON a.article_id = ar.id " +          // 关联点赞的文章
            "LEFT JOIN sys_user author ON ar.author_id = author.id " +  // 关联文章的作者（而不是点赞用户）
            "${ew.customSqlSegment}")
    Page<LikesDTO> selectArticlePageWithAuthor(Page<LikesDTO> page, @Param(Constants.WRAPPER) Wrapper<Likes> wrapper);
}
